var shell = require("shelljs");
const fs = require("fs");
const {resolve} = require('path');

const resolvePath = resolve();

function getShell(code, msg) {
    const retGit = shell.exec(code);
    if (retGit.code != 0) {
        shell.cd(resolve('./'));
        console.log('\x1b[31m%s\x1b[0m', msg);
        return false;
    }
    return true;
}

function cuurentResolve(path) {
    if(path){
        return  resolvePath + path
    }
    return  resolvePath
}

function themeList() {
    const themesFlie = fs.readdirSync("./src/theme");
    const blacklist = [".DS_Store", ".git", ".gitignore", ".vscode", "system","customtemp29831", "customtemp34484","customtemp39391","default","component","test"];
    return themesFlie.filter((item) => {
        return !blacklist.includes(item) && item.indexOf("customtemp") === -1;
    });
}

function branchCheck(branch) {
    const branchRet = shell.exec(`git branch`);
    return branchRet.stdout.indexOf(branch) === -1;
}
module.exports = { getShell, themeList, branchCheck ,cuurentResolve};
